
s = 0
for n in xrange(1, 10**6):
     if str(n) == str(n)[::-1]:
         b =  bin(n)[2:]
         if b == b[::-1]:
            s += n
print s

